<script setup>
import { onMounted, ref } from 'vue';
import { AppstoreFilled, UserOutlined } from '@ant-design/icons-vue';
import { useUserStore } from '@/store';

const userStore = useUserStore();
const emits = defineEmits(['changeTheme']);
const activeTheme = ref('light');

function toggleTheme(theme) {
    activeTheme.value = theme;
    emits('changeTheme', theme);
}

onMounted(() => {
    activeTheme.value = document.documentElement.getAttribute('data-theme') || 'light';
})

</script>

<template>
    <div class="layout-header">
        <div class="app-info">
            <AppstoreFilled class="app-icon" />
            <p class="app-name">ADR管理平台</p>
        </div>
        <div style="display: flex; align-items: center;">
            <div style="margin-right: 14px;">
                <a-button v-if="activeTheme === 'light'" type="link"  @click="toggleTheme('dark')">
                    <img src="@/assets/images/moon.svg" alt="" style="width: 18px;height: 18px;">
                </a-button>
                <a-button v-if="activeTheme === 'dark'" type="link" @click="toggleTheme('light')">
                    <img src="@/assets/images/sun.svg" alt="" style="width: 18px;height: 18px;">
                </a-button>
            </div>
            <div class="user-info">
                <a-avatar style="background-color: #87d068">
                    <template #icon><UserOutlined /></template>
                </a-avatar>
                <p class="user-name">{{ userStore.userName }}</p>
            </div>
        </div>
    </div>
</template>

<style lang="less" scoped>
.layout-header {
    height: 48px;
    background-color: @bg-color;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    border-bottom: 1px solid @border-color;

    .app-info {
        display: flex;
        align-items: center;

        .app-icon {
            font-size: 32px;
            color: @primary-color;
        }

        .app-name {
            font-size: 24px;
            color: @primary-color;
            font-weight: bold;
            margin-left: 7px;
        }
    }

    .user-info {
        display: flex;
        align-items: center;

        .user-name {
            margin-left: 14px;
        }
    }
}
</style>